@extends('home.seller.layout.index')

@section('content')
	<div class="mws-panel grid_8">
    	<div class="mws-panel-header">
        	<span><i class="icon-table"></i> 添加商品</span>
        </div>
        <div class="mws-panel-body no-padding">
        	<form id="mws-validate" class="mws-form" action="/home/seller/goods/insert" novalidate="novalidate" method="post" enctype="multipart/form-data">
            	{{ csrf_field() }}
            	<div id="mws-validate-error" class="mws-form-message error" style="display:none;"></div>
            	<div class="mws-form-inline">
                	<div class="mws-form-row">
                    	<label class="mws-form-label">商品标题</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="goodsname" class="required large" value="" placeholder="请输入商品的标题（用于搜索商品）">
                        </div>
                    </div>
                	<div class="mws-form-row">
                    	<label class="mws-form-label">商品详情介绍</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="details" class="required email large" value="" placeholder="请输入商品详情介绍">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品名称</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="title" class="required email large" value="" placeholder="请输入商品名称">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品价格</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="price" class="required digits large" value="" placeholder="请输入价格，必须输入整数">
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品数量</label>
                    	<div class="mws-form-item">
                        	<input type="text" name="inventory" class="required digits large" value="" placeholder="请输入商品的数量，必须输入整数">
                        </div>
                    </div>
                    <div class="mws-form-row">
                        <div class="mws-form-cols">
                            <div class="mws-form-col-4-8">
                                <label class="mws-form-label">商品属性（最多5种属性）例如：颜色、大小、重量等</label>
                                <div class="mws-form-item" id="attrbute_key1">
                                    <input type="text" style="margin-top:5px" name="attrbute_key1" value="" placeholder="请输入商品的属性1">
                                </div>
                            </div>
                            <div class="mws-form-col-4-8">
                                <label class="mws-form-label">属性值</label>
                                <div class="mws-form-item" id="attrbute_val1">
                                    <input type="text" style="margin-top:5px" name="attrbute_val1" value="" placeholder="请输入商品的属性1的值">
                                </div>
                            </div>
                        </div>
                         <div class="mws-form-cols">
	                        <div class="mws-form-col-7-8">
	                            <label class="mws-form-label"></label>
	                        </div>
                            <div class="mws-form-col-1-8">
                            	<button data-toggle="dropdown" class="btn btn-warning dropdown-toggle" aria-expanded="true" style="margin-top:5px" id="attrbute_add" onclick="myadd(this)">添加属性</button>
                            </div>
                        </div>
                    </div>
                	<div class="mws-form-row">
                	 	<div class="mws-form-cols">
	                	 	<label class="mws-form-label"  id="class_name">商品分类</label>
	                	 	<input type="hidden" name='classname' value="" id='class_classname'>
		                	@foreach($arr as $k => $v)
		                	<div class="mws-form-col-1-8" id="hide">
		                    	<div class="mws-form-item">
										<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" aria-expanded="true" onclick="fun(this)">{{ $v['classname'] }} <span class="caret"></span></button>
										<ul style="list-style:none;margin:2px 0px 0px 0px;padding:0px;display:none">
											<li>
												<select onchange="classnamea(this)">
													<option value="0" selected disabled>--请选择--</option>
			                    					@foreach($v['sub'] as $kk => $vv)
														<option value="{{ $vv['classname'] }}" >{{ $vv['classname'] }}</option>
													@endforeach
		                    					</select>
	                    					</li>
										</ul>
		                        </div>
	                        </div>
	                        @endforeach
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品头像</label>
                    	<div class="mws-form-item">
                        	<input type="file" name="picture" >
                        </div>
                    </div>
                    <div class="mws-form-row">
                    	<label class="mws-form-label">商品详情图</label>
                    	<div class="mws-form-item">
                        	<!-- 加载编辑器的容器 -->
						    <script id="container" name="content" type="text/plain" style="width:100%">
						        
						    </script>
                        </div>
                    </div>
                </div>
                <div class="mws-button-row">
                	<input type="submit" class="btn btn-danger" value="添加商品">
                </div>
            </form>
        </div>    	
    </div>
@endsection

@section('script')
    <script src="/homeassets/seller/custom-plugins/fileinput.js"></script>
	<!-- 配置文件 -->
    <script type="text/javascript" src="/homeassets/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/homeassets/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var ue = UE.getEditor('container');
    </script>
    <script>
    	// 分类隐藏和显示
    	function fun(a) {
    		$('#hide ul').hide();
    		$(a).next().toggle();

    	}


    		function classnamea(b){
    		
    			$('#class_classname').val($(b).val());
    		}


        // 添加属性
	    var count = 1;
		function myadd() {
			if (count < 5) {
				count++;
				$('#attrbute_key'+(count-1)).after('<div class="mws-form-item" id="attrbute_key'+count+'"><input type="text" style="margin-top:5px" name="attrbute_key'+count+'" value="" placeholder="请输入商品的属性'+count+'"></div>');
				$('#attrbute_val'+(count-1)).after('<div class="mws-form-item" id="attrbute_val'+count+'"><input type="text" style="margin-top:5px" name="attrbute_val'+count+'" value="" placeholder="请输入商品的属性'+count+'的值"></div>');
				

			} else {
				$('#attrbute_add').fadeOut('slow');
				return;
			}
		}
    </script>
@endsection